<html>
<head>
  <meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=ISO-8859-1">
  <title>kernelproj.m</title>
<link rel="stylesheet" type="text/css" href="../../m-syntax.css">
</head>
<body>
<code>
<span class=defun_kw>function</span>&nbsp;<span class=defun_out>out_data</span>=<span class=defun_name>kernelproj</span>(<span class=defun_in>in_data,&nbsp;model</span>)<br>
<span class=h1>%&nbsp;KERNELPROJ&nbsp;Kernel&nbsp;projection.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Synopsis:</span></span><br>
<span class=help>%&nbsp;&nbsp;Y&nbsp;=&nbsp;kernelproj(X,&nbsp;model)</span><br>
<span class=help>%&nbsp;&nbsp;out_data&nbsp;=&nbsp;kernelproj(in_data,&nbsp;model)</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Description:</span></span><br>
<span class=help>%&nbsp;&nbsp;Y&nbsp;=&nbsp;kernelproj(X,&nbsp;model)&nbsp;this&nbsp;function&nbsp;maps&nbsp;input&nbsp;vectors&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;X&nbsp;[dim&nbsp;x&nbsp;num_data]&nbsp;onto&nbsp;vectors&nbsp;Y&nbsp;[new_dim&nbsp;x&nbsp;num_data]</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;using&nbsp;the&nbsp;kernel&nbsp;projection</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Y(:,i)&nbsp;=&nbsp;Alpha'&nbsp;*&nbsp;kernel(sv.X,&nbsp;X(:,i),&nbsp;ker,&nbsp;arg)&nbsp;+&nbsp;b</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;where&nbsp;parameters&nbsp;of&nbsp;the&nbsp;projection&nbsp;are&nbsp;given&nbsp;in&nbsp;model:</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Alpha&nbsp;[nsv&nbsp;x&nbsp;new_dim]&nbsp;Multipliers.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.b&nbsp;[new_dim&nbsp;x&nbsp;1]&nbsp;Bias.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.sv.X&nbsp;[dim&nbsp;x&nbsp;nsv]&nbsp;Vectors.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.options.ker&nbsp;[string]&nbsp;Kernel&nbsp;identifier.</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.options.arg&nbsp;[1&nbsp;x&nbsp;narg]&nbsp;Kernel&nbsp;argument.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;out_data&nbsp;=&nbsp;kernelproj(in_data,&nbsp;model)&nbsp;assumes&nbsp;that&nbsp;in_data</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;is&nbsp;a&nbsp;structure&nbsp;containing&nbsp;vectors&nbsp;X&nbsp;and&nbsp;labels&nbsp;y.&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;The&nbsp;output&nbsp;structute&nbsp;out_data&nbsp;is&nbsp;constructed&nbsp;as&nbsp;</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out_data.X&nbsp;=&nbsp;kernelproj(in_data.X,&nbsp;model)</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out_data.y&nbsp;=&nbsp;in_data.y</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Example:</span></span><br>
<span class=help>%&nbsp;&nbsp;help&nbsp;kpca;</span><br>
<span class=help>%&nbsp;&nbsp;help&nbsp;gda;</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;See&nbsp;also&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;GDA,&nbsp;KPCA,&nbsp;LINPROJ,&nbsp;KERNEL.</span><br>
<span class=help>%</span><br>
<hr>
<br>
<span class=help1>%&nbsp;<span class=help1_field>About:</span>&nbsp;Statistical&nbsp;Pattern&nbsp;Recognition&nbsp;Toolbox</span><br>
<span class=help1>%&nbsp;(C)&nbsp;1999-2003,&nbsp;Written&nbsp;by&nbsp;Vojtech&nbsp;Franc&nbsp;and&nbsp;Vaclav&nbsp;Hlavac</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.cvut.cz"&gt;Czech&nbsp;Technical&nbsp;University&nbsp;Prague&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.feld.cvut.cz"&gt;Faculty&nbsp;of&nbsp;Electrical&nbsp;Engineering&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://cmp.felk.cvut.cz"&gt;Center&nbsp;for&nbsp;Machine&nbsp;Perception&lt;/a&gt;</span><br>
<br>
<span class=help1>%&nbsp;<span class=help1_field>Modifications:</span></span><br>
<span class=help1>%&nbsp;19-sep-2004,&nbsp;VF,&nbsp;core&nbsp;of&nbsp;the&nbsp;function&nbsp;rewritten&nbsp;to&nbsp;C</span><br>
<span class=help1>%&nbsp;14-may-2004,&nbsp;VF</span><br>
<span class=help1>%&nbsp;4-may-2004,&nbsp;VF</span><br>
<br>
<hr>
<span class=keyword>if</span>&nbsp;isstruct(in_data)==1,<br>
&nbsp;&nbsp;out_data&nbsp;=&nbsp;in_data;<br>
<br>
&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;~isempty(model.Alpha)&nbsp;&&nbsp;isfield(model,&nbsp;<span class=quotes>'Alpha'</span>),<br>
&nbsp;&nbsp;&nbsp;&nbsp;out_data.X&nbsp;=&nbsp;kernelproj_mex(in_data.X,&nbsp;model.Alpha,&nbsp;model.b,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;model.sv.X,&nbsp;model.options.ker,&nbsp;model.options.arg);<br>
&nbsp;&nbsp;<span class=keyword>else</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;[dim,num_data]=size(in_data.X);<br>
&nbsp;&nbsp;&nbsp;&nbsp;out_data.X&nbsp;=&nbsp;model.b*ones(1,num_data);<br>
&nbsp;&nbsp;<span class=keyword>end</span><br>
&nbsp;&nbsp;<br>
<span class=keyword>else</span><br>
&nbsp;&nbsp;<span class=keyword>if</span>&nbsp;~isempty(model.Alpha)&nbsp;&&nbsp;isfield(model,<span class=quotes>'Alpha'</span>),<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;out_data&nbsp;=&nbsp;kernelproj_mex(in_data,&nbsp;model.Alpha,&nbsp;model.b,&nbsp;...<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;model.sv.X,&nbsp;model.options.ker,&nbsp;model.options.arg);<br>
&nbsp;&nbsp;<span class=keyword>else</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;[dim,num_data]=size(in_data);<br>
&nbsp;&nbsp;&nbsp;&nbsp;out_data&nbsp;=&nbsp;model.b*ones(1,num_data);<br>
&nbsp;&nbsp;<span class=keyword>end</span><br>
<span class=keyword>end</span><br>
<br>
<span class=jump>return</span>;<br>
<span class=comment>%&nbsp;EOF</span><br>
</code>
